package com.haoshuang.zhouzhoubang.ui.vm

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.okRequest
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.bean.CallBean
import com.haoshuang.zhouzhoubang.model.bean.OrderDetail2Bean
import com.haoshuang.zhouzhoubang.model.bean.YyBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class AppointmentCustomerViewModel : BaseViewModel() {
    val getData3 = StatefulMutableLiveData<Any>()
    fun getData3(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("/api/master_order/add_confirm_order_time", *params,
                onStart = {
                    getData3.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData3.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData3.value = StateData.Success(it)
                })
        }
    }

    val getConfirmOrderTimeData = StatefulMutableLiveData<YyBean>()
    fun getConfirmOrderTime(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<YyBean>("api/master_order/confirm_order_time", *params,
                onStart = {
                    getConfirmOrderTimeData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getConfirmOrderTimeData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getConfirmOrderTimeData.value = StateData.Success(it)
                })
        }
    }

    val getOrderDetailData = StatefulMutableLiveData<OrderDetail2Bean>()
    fun getOrderDetail(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<OrderDetail2Bean>("api/master_order/get_master_order_detail", *params,
                onStart = {
                    getOrderDetailData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getOrderDetailData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getOrderDetailData.value = StateData.Success(it)
                })
        }
    }

    /**
     * 转单操作
     */
    val transferOrderData = StatefulMutableLiveData<Boolean>()
    fun transferOrder(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            okRequest("api/master_order/transferOrders", *params,
                onStart = {
                    transferOrderData.value = StateData.Loading
                },
                onError = { code, msg ->
                    transferOrderData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    transferOrderData.value = StateData.Success(true)
                })
        }
    }
}